Folder enumeration sample


Windows Runtime
Storage
Windows RT
en-US
11/25/2013

This sample shows how to enumerate the top-level files and folders inside a location (like a folder, device, or network location), and how to use queries to enumerate all files inside a location by sorting them into file groups.

This sample uses Windows.Storage and Windows.Storage.Search APIs, including StorageFolder and StorageFolderQueryResult.

The sample demonstrates these tasks:

  1. Enumerate top-level files and subfolders of a folder

    Uses the StorageFolder.GetFilesAsync and StorageFolder.GetFoldersAsync methods to enumerate only the top-level files and folders (the immediate children) of the location (in this case, the Pictures library). For a walkthrough of this task, see Quickstart: Accessing files programmatically.

  2. Query all the files in a folder (and its subfolders) and create groups of files to enumerate

    Uses the StorageFolder.CreateFolderQueryWithOptions method to sort all files in the location (in this case, the Pictures library) into groups based on the criteria that you specify and uses a StorageFolderQueryResult.GetFoldersAsync method to retrieve the resulting file groups.

    File groups are virtual folders that are represented by StorageFolder objects. The files in a file group have the criteria that you specify in common. For example, as the sample shows, the files in a group might have the same rating.

    For a walkthrough of this task, see Quickstart: Accessing files programmatically.

  3. Query all the files in a folder (and its subfolders) and retrieve file properties as a part of getting results for the query

    Uses QueryOptions.SetPropertyPrefetch to specify properties to retrieve when the query is created. StorageFolder.CreateFolderQueryWithOptions and GetFilesAsync are used to create the query and enumerate results. Similarly, you can use SetThumbnailPrefetch to retrieve thumbnails as a part of creating the query.

    Using SetPropertyPrefetch and SetThumbnailPrefetch might make the query take longer to execute, but will make accessing large amounts of file information more efficient.

Additional important APIs in this sample include:

To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.

To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.

Note  For Windows 8 app samples, download the Windows 8 app samples pack. The samples in the Windows 8 app samples pack will build and run only on Microsoft Visual Studio 2012.

Related topics

Windows 8 app samples
Related samples
Programmatic file search sample
File access sample
File and folder thumbnail sample

Related technologies

Windows.Storage namespace, Windows.Storage.Search namespace

Operating system requirements

Client
Windows 8.1
Server
Windows Server 2012 R2

Build the sample

  1. Start Visual Studio 2013 and select File > Open > Project/Solution.
  2. Go to the directory in which you unzipped the sample. Go to the directory named for the sample, and double-click the Microsoft Visual Studio Solution (.sln) file.
  3. Press F6 or use Build > Build Solution to build the sample.

Run the sample

To debug the app and then run it, press F5 or use Debug > Start Debugging. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.